<?php
	$template->_template_read("./Applications/monalisa/Templates/edit.html");
	
	$template->_template_assign("CAPTION_MLED1", (string)$language->common->value_35);
	$template->_template_assign("CAPTION_MLED2", (string)$language->common->value_7);
	$template->_template_assign("CAPTION_MLED3", (string)$language->common->value_36);
	$template->_template_assign("CAPTION_MLED4", (string)$language->common->value_37);
	$template->_template_assign("CAPTION_MLED5", (string)$language->common->value_38);
	$template->_template_assign("CAPTION_MLED6", (string)$language->common->value_42);
	$template->_template_assign("CAPTION_MLED7", (string)$language->common->value_39);
	$template->_template_assign("CAPTION_MLED8", (string)$language->common->value_12);
	$template->_template_assign("CAPTION_MLED9", (string)$language->common->value_13);
	$template->_template_assign("CAPTION_MLED10", (string)$language->common->value_40);
	$template->_template_assign("CAPTION_MLED11", (string)$language->common->value_15);
	$template->_template_assign("CAPTION_MLED12", (string)$language->common->value_41);
	$template->_template_assign("CAPTION_MLED13", (string)$language->buttons->value_5);
	$template->_template_assign("CAPTION_MLED14", (string)$language->msgs->value_2);
	$template->_template_assign("CAPTION_MLED15", (string)$language->legends->value_6);
	
	$expo = sqlite_open($_GET["edit"]);
	$desc = sqlite_array_query($expo, "SELECT * FROM expo WHERE (type='desc') LIMIT 1", SQLITE_ASSOC);
	$exhibits = sqlite_array_query($expo, "SELECT * FROM expo WHERE (type='file' OR type='folder')", SQLITE_ASSOC);
	$date = sqlite_array_query($expo, "SELECT * FROM expo WHERE (type='date') LIMIT 1", SQLITE_ASSOC);
	$tinyURL = sqlite_array_query($expo, "SELECT * FROM expo WHERE (type='tiny') LIMIT 1", SQLITE_ASSOC);
	$template->_template_assign("EXPONAME", $desc[0]['exhibit']);
	$template->_template_assign("EXPOFILE", $_GET["edit"]);
	$template->_template_assign("ERSTELLUNGSDATUM", $expo->Erstellt);
	if (trim($tinyURL[0]["exhibit"]) != ""){
		$template->_template_assign("TINYURL", $tinyURL[0]["exhibit"]);
	}
	$entrys = array();
		foreach ($exhibits as $row){
			$entrys["ELEMENT"] = $row['exhibit'];
			$entrys["ID"] = $row['id'];
			$template->_template_append("ENTRYS", $entrys);
		}
	$path_to = $_GET["edit"];
	$expo = pathinfo($_GET["edit"]);
	$expo = $expo["filename"];
	$server_name = $_SERVER["SERVER_NAME"];
	$path = str_replace("/main.php", "", $_SERVER["SCRIPT_NAME"]);
	$u = "http://$server_name$path/exposition.php?expo=$expo";
	$expos = array();
	$handle = opendir("./Applications/monalisa/Expositions");
	while ($file = readdir ($handle)) {
		if($file != "." AND $file != ".." AND substr($file, -5) == ".expo"){
			if ($bg_color == 1){
				$entrys["BG_COLOR"] = "#dedede";
				$bg_color++;
			} else {
				$entrys["BG_COLOR"] = "#efefef";
				$bg_color = 1;
			}
			$compl = "./Applications/monalisa/Expositions/".$file;
			$expo = sqlite_open($compl);
			$desc = sqlite_array_query($expo, "SELECT exhibit FROM expo WHERE (type='desc') LIMIT 1", SQLITE_ASSOC);	
			$expos["EXPO_COMPL"] = $compl;
			$expos["EXPO"] = $desc[0];
			$template->_template_append("EXPOS", $expos);
			sqlite_close($expo);
		}
	}
	
	$template->_template_assign("ORIG_URL", $u);
	
	//sqlite_close($expo);
?>